#include <assert.h>
#include <memory.h>
#include <ctime>
#include <cstdlib>
#include "Cryptogram.h"
#include "des_min_inc.h"
#include "a_md5.h"

Cryptogram::Cryptogram(void)
{
}

Cryptogram::~Cryptogram(void)
{
}

Cryptogram* Cryptogram::CreateDes()
{
	Cryptogram* p = new CDes;
	assert(p != 0);
	return p;
}



CDes::CDes() 
{
}

CDes::~CDes()
{

}


STATUS CDes::Encrypt(GUINT8* pSrc, GUINT32 srcLen, GUINT8* pDes, GUINT32 desLen, GUINT8* key)
{
	if(0 == des_min_do(pSrc, srcLen,  pDes, desLen, key, DES_ENCRYPT))
	{
		return RE_FAIL;
	}
	return RE_SUCCEED;
}

STATUS CDes::Decrypt(GUINT8* pSrc, GUINT32 srcLen, GUINT8* pDes, GUINT32 desLen, GUINT8* key)
{
	if(0 == des_min_do(pSrc, srcLen,  pDes, desLen, key, DES_DECRYPT))
	{
		return RE_FAIL;
	}
	return RE_SUCCEED;
}


HashAgorithm::HashAgorithm(void)
{
}

HashAgorithm::~HashAgorithm(void)
{
}

HashAgorithm* HashAgorithm::CreateMD5()
{
	HashAgorithm* p = new MD5;
	assert(p != 0);
	return p;
}

MD5::MD5(void)
{
}

MD5::~MD5(void)
{
}

STATUS MD5::Hash(GUINT8* pSrc, GUINT32 srcLen, GUINT8* pDes, GUINT32 desLen)
{
	if (desLen < 16)
	{
		return RE_FAIL;
	}
	hmac_md5(pSrc, srcLen, pDes);
	return RE_SUCCEED;
}

